package com.java246;

import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        // 创建集合对象
        TreeSet<Student> ts = new TreeSet<Student>();

        // 创建信息
        Student s1 = new Student("a", 1);
        Student s2 = new Student("c", 3);
        Student s3 = new Student("b", 2);
        Student s4 = new Student("d", 2);

        // 添加信息
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);

        // 遍历集合
        for (Student s : ts) {
            System.out.println(s.getName() + ":" + s.getAge());
        }
    }
}
